/*
 * Copyright © 2011 Breachwalls & Company Inc. and other authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.breachwalls.h2p.plugin.prescription.web.action;

import java.util.List;

import org.springframework.webflow.execution.RequestContext;

import com.breachwalls.eap.core.errors.ErrorMessage;
import com.breachwalls.eap.core.exceptions.VerificationLogicException;
import com.breachwalls.h2p.plugin.prescription.web.form.PrescriptionForm;

/**
 * 処方箋登録フォームアクション.
 * @author Ken Todoroki
 * @version $Revision$
 */
public class PrescriptionFormAction extends PrescriptionFormActionSupport {

    public String initialize(RequestContext context) {
        PrescriptionForm form = new PrescriptionForm();
        setPrescriptionForm(context, form);
        return success();
    }

    public String confirm(RequestContext context) {
        try {
            PrescriptionForm form = getPrescriptionForm(context);
            getPrescriptionFormService().execConfirmPrescriptionForm(form);
        } catch (VerificationLogicException e) {
            List<ErrorMessage> errors = e.getErrorMessages();
            saveErrorMessages(context, errors);
            return error();
        }
        return success();
    }

    public String create(RequestContext context) {
        try {
            PrescriptionForm form = getPrescriptionForm(context);
            getPrescriptionFormService().execCreatePrescriptionForm(form);
        } catch (VerificationLogicException e) {
            List<ErrorMessage> errors = e.getErrorMessages();
            saveErrorMessages(context, errors);
            return error();
        }
        return success();
    }

}
